package org.gdpi.boot1.controller;

import org.gdpi.boot1.pojo.Product;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AxiosController {
    @RequestMapping("/hel")
    public String helloAxios(String name,Integer age){
        return "测试成功"+name+":"+age;
    }

    /**
     * 如果异步请求提交自定义的js对象
     * 服务器接受参数需要添加@RequestBody注解
     * js对象里属性的名称要和实体类里对象属性名保持一致
     */
    @RequestMapping("/postAxios")
    public String postAxios(@RequestBody Product product){
        System.out.println(product);
        return "post请求成功";
    }

    @RequestMapping("/bmi")
    public String bmi(double h,double w) {
        //身体质量指数，是BMI计算公式
        double bmi = w / (h * h);
        if (bmi < 18.5) {
            return "真是瘦";
        } else if (bmi < 24) {
            return "正常标准";
        } else {
            return "该减肥了";
        }
    }
}
